package cpt202.project.service.impl;

import cpt202.project.dao.RecordMapper;
import cpt202.project.entity.Record;
import cpt202.project.service.RecordService;
import cpt202.project.service.exception.DeleteException;
import cpt202.project.service.exception.InsertException;
import cpt202.project.service.exception.ModifyException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RecordServiceimpl implements RecordService {
    @Autowired
    private RecordMapper recordMapper;

    @Override
    public Integer add(Record record) {
        recordMapper.addRec(record);
        Integer newrecID = record.getRecordId();
        if (newrecID<=0){
            throw new InsertException("插入出现未知异常");
        }
        return newrecID;
    }

    @Override
    public void delete(Integer id){
        Integer rows=recordMapper.deleteRec(id);
        if (rows!=1){
            throw new DeleteException("删除出现未知异常");
        }
    }

    @Override
    public void Modify(Record record){
        Integer rows=recordMapper.updateRec(record);
        if (rows!=1){
            throw new ModifyException("修改出现未知异常");
        }
    }
}
